#include<cmath>
#include<cctype>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define re register int
using namespace std;
inline int read(){
	int x=0,w=1;
	char ch=getchar();
	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
	if(ch=='-') w=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-48,ch=getchar();
	return x*w;
}
const char *Const=" ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char s[101];

inline void Solve1() {
    int i=0,j=0,num1=0,num2=0;
    int t[101];
    for(++i;isdigit(s[i]);++i) num2=num2*10+s[i]-'0';
    for(++i;s[i];++i) num1=num1*10+s[i]-'0';
    for(;num1;num1=num1/26-!(num1%26)) { 
        if(num1%26) t[++j]=num1%26;
        else t[++j]=26;   
    }
    for(;j;--j) putchar(Const[t[j]]);
    printf("%d\n",num2);
}

inline void Solve2() {
    int i=0,num1=0,num2=0;
    for(;isupper(s[i]);++i) (num2*=26)+=s[i]-'A'+1;
    for(;s[i];++i) (num1*=10)+=s[i]-'0';
    printf("R%dC%d\n",num1,num2);
}

int main() {
	freopen("1b.in","r",stdin);
	freopen("1b.out","w",stdout);
    int n;
    bool flag;
	n=read();
    for(re i=1;i<=n;++i) {
        scanf("%s",s);
        flag=0;
        for(int i=0;s[i]&&!flag;++i) if(i&&isdigit(s[i-1])&&isupper(s[i])) flag=1; //若字母前出现数字,一定是(R,C)法
        if(flag) Solve1();
        else Solve2();
    }
    return 0;
}